class Diary {
  final int? id;
  final String date;
  final String content;
  final int? moodId;
  final String createdAt;
  final List<MoodTag>? tags;

  Diary({
    this.id,
    required this.date,
    required this.content,
    this.moodId,
    required this.createdAt,
    this.tags,
  });

  // 从数据库映射创建Diary对象
  factory Diary.fromMap(Map<String, dynamic> map, {List<MoodTag>? tags}) {
    return Diary(
      id: map['id'] as int?,
      date: map['date'] as String,
      content: map['content'] as String,
      moodId: map['mood_id'] as int?,
      createdAt: map['created_at'] as String,
      tags: tags,
    );
  }

  // 将Diary对象转换为数据库映射
  Map<String, dynamic> toMap() {
    return {
      'id': id,
      'date': date,
      'content': content,
      'mood_id': moodId,
      'created_at': createdAt,
    };
  }

  // 复制并修改Diary对象
  Diary copyWith({
    int? id,
    String? date,
    String? content,
    int? moodId,
    String? createdAt,
    List<MoodTag>? tags,
  }) {
    return Diary(
      id: id ?? this.id,
      date: date ?? this.date,
      content: content ?? this.content,
      moodId: moodId ?? this.moodId,
      createdAt: createdAt ?? this.createdAt,
      tags: tags ?? this.tags,
    );
  }
}

class MoodTag {
  final int? id;
  final String name;
  final String category;

  MoodTag({
    this.id,
    required this.name,
    required this.category,
  });

  // 从数据库映射创建MoodTag对象
  factory MoodTag.fromMap(Map<String, dynamic> map) {
    return MoodTag(
      id: map['id'] as int?,
      name: map['name'] as String,
      category: map['category'] as String,
    );
  }

  // 将MoodTag对象转换为数据库映射
  Map<String, dynamic> toMap() {
    return {
      'id': id,
      'name': name,
      'category': category,
    };
  }
} 